package main

import (
	"fmt"
	"sort"
)

func main() {
	//var map3 = map[string]int{"php":7,"java":66}
	//
	//fmt.Println(map3)
	var map1 map[string]int
	if map1 == nil {
		map1 = make(map[string]int)
	}
	fmt.Println(map1 == nil)

	//存储键值对
	map1["sss"] = 233
	fmt.Println(map1["gg"])

	//获取
	value, ok := map1["sss"]
	if ok {
		fmt.Println("value", value)
	} else {
		fmt.Println("value", value)
	}

	//修改 和 新增一个道理
	map1["sss"] = 233

	//删除
	delete(map1, "sss")
	fmt.Println(map1)

	//无序，遍历
	map2 := make(map[int]string)
	map2[1] = "1"
	map2[2] = "2"
	map2[3] = "3"

	for key, value := range map2 {
		fmt.Println(key, value)
	}

	//有序，遍历

	map3 := make(map[int]string)
	map3[4] = "hello1"
	map3[5] = "a1"
	map3[9] = "c1"
	map3[1] = "b1"
	sss := make([]int, 0, len(map3))
	for k, _ := range map3 {
		sss = append(sss, k)
	}
	sort.Ints(sss)
	fmt.Println(sss)
	for _, vv := range sss {
		fmt.Println(map3[vv])
	}

}
